<template>
	<div>
		<div class="box-card">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
				<el-breadcrumb-item><a href="/">审核管理</a></el-breadcrumb-item>
				<el-breadcrumb-item>节目集审核管理</el-breadcrumb-item>
			</el-breadcrumb>
		</div>

		<div>
			<el-card class="box-card">

				<el-row :gutter="15">
					<el-form ref="elForm" :model="formData" :rules="rules" size="mini" label-width="100px">
						<el-col :span="6">
							<el-form-item label="节目集名称" prop="name">
								<el-input v-model="formData.name" placeholder="请输入单行文本节目集名称" clearable
									:style="{width: '100%'}">
								</el-input>
							</el-form-item>
						</el-col>

						<el-col :span="9">
							<el-form-item>
								<el-button type="zz3" @click="submitForm" size="mini">搜索</el-button>
								<el-button @click="resetForm" size="mini">重置</el-button>
							</el-form-item>
						</el-col>
					</el-form>
				</el-row>
				<!-- <el-button type="primary" @click="openadd">新增节目集</el-button> -->
			</el-card>
		</div>

		<div class="box-card">
			<el-table :data="tableData" style="width: 100%">
				<el-table-column prop="id" label="ID" width="33"> </el-table-column>
				<el-table-column prop="name" label="名称" width="220"> </el-table-column>
				<el-table-column prop="UUID" label="UUID"> </el-table-column>
				<el-table-column prop="created_at" label="创建时间"> </el-table-column>
				<el-table-column prop="category" label="分类" width="60"> </el-table-column>
				<el-table-column prop="sndCategory" label="二级分类"> </el-table-column>
				<el-table-column prop="seriesAmount" label="节目总集数" width="80"> </el-table-column>
				<el-table-column prop="a5" label="录入员"> </el-table-column>


				<el-table-column label="审核状态" width="100">
					<template slot-scope="scope">

						<el-switch v-model="scope.row.shenhe" active-color="#13ce66" inactive-color="#ff4949"
							:active-value="1" @change="shenhe(scope.row)" :inactive-value="0">
						</el-switch>
					</template>
				</el-table-column>
				
				<el-table-column   label="推送数据(总/已推/未推/未审)">
					
					<template slot-scope="scope">
					
						<span style="font-size: 18px;">{{scope.row.a1}}/{{scope.row.a2}}/{{scope.row.a3}}/{{scope.row.a4}}</span>
					</template>
					
					</el-table-column>
				
				
	 

				<el-table-column label="操作">
					<template slot-scope="scope">
						<el-button size="mini" type="danger" @click="handleEdit(scope.row)">编辑</el-button>
						<!-- <el-button size="mini" type="zz3" @click="shenhe(scope.row)">审核</el-button> -->
						<el-button size="mini" type="zz4" @click="send(scope.row)">推送</el-button>
					</template>
				</el-table-column>
			</el-table>

			<el-card class="box-card1">

				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
					:current-page="page.page" :page-sizes="[2, 10, 30, 80]" :page-size="page.sizes"
					layout="total, sizes, prev, pager, next, jumper" :total="page.total">
				</el-pagination>

			</el-card>


		</div>

		<el-dialog title="提示" :visible.sync="addwindow" width="66%" :before-close="handleClose">
			<span>添加节目集：</span>

			<jmjinfo @tjinfo="tjinfoadd" :data="formdatas"></jmjinfo>
		</el-dialog>

	</div>
</template>

<script>
	import jmjinfo from "./jmj_info.vue"

	export default {
		components: {
			jmjinfo
		},
		data() {
			return {
				addwindow: false,
				formdatas: {},
				tableData: [],
				page: {
					page: 1,
					sizes: 10,
					total: undefined
				},
				formData: {
					name: '',
					id: undefined,
				},
				rules: {
					name: [{
						required: true,
						message: '请输入单行文本节目集名称',
						trigger: 'blur'
					}],
					id: [{
						required: true,
						message: '请输入单行文本节目集号',
						trigger: 'blur'
					}],
				},
			}

		},

		created() {
			this.getdata()
		},

		methods: {
			resetForm(){
				this.formData={
						name: '',
						id: undefined,
					}
					this.getdata()
			},
			send(e){
				console.log(e)
				if(e.shenhe != 1){
					this.$message.error('没有审核的无法进行推送');
					return false
				}
				
				this.$http.get('jmj/send?id='+e.id).then(r=>{
					 
					if (r.code == 10000) {
						this.$message({
							message: '推送完成',
							type: 'success'
						});
						this.getdata()
					} else {
						this.$message.error('审核失败');
					}
				})
 
			},
			// sendinfo(e){
			// 	this.$http.post('http://stage-bzo.cloud.ottcn.com/newpiper/service/program/hengshui/push',e).then(r=>{
			// 		console.log(r)
			// 	})
			// },
			shenhe(e) {
				console.log(e)
				this.$http.get('jmj/shenhe?id=' + e.id).then(res => {
					console.log(res)

					if (res.code == 10000) {
						this.$message({
							message: '审核成功',
							type: 'success'
						});
						this.getdata()
					} else {
						this.$message.error('审核失败');
					}
				})
			},
			handleEdit(e) {
				console.log(e)
				this.addwindow = true
				this.formdatas = e

			},
			getdata() {
				this.$http.get('jmj/getjmjlistsh?page=' + this.page.page + '&size=' + this.page.sizes + '&name=' + this
					.formData.name).then(res => {
					console.log(res)
					this.tableData = res.data.data
					this.page.total = res.data.total

				})
			},
			handleSizeChange(val) {
				console.log(`每页 ${val} 条`);
				this.page.sizes = val
				this.getdata()
			},
			handleCurrentChange(val) {
				console.log(`当前页: ${val}`);
				this.page.page = val
				this.getdata()
			},
			openadd() {
				this.addwindow = true
				this.formdatas = {}
			},
			tjinfoadd(e) {
				e.a1 = undefined
				e.a2 = undefined
				e.a3 = undefined
				e.a4 = undefined
				e.a5 = undefined
				e.a6 = undefined

				this.$http.post('jmj/addjmj', e).then(res => {
					console.log(res)
					if (res.code == 10000) {
						this.$message({
							message: '添加成功',
							type: 'success'
						});
						this.addwindow = false
						this.$router.go(0)
					} else {
						this.$message.error('添加失败');
					}
				})


			},
			handleClose() {
				this.$router.go(0)
			},
			submitForm() {
				this.getdata()
			}


		},
	}
</script>

<style>
	.text {
		font-size: 14px;
	}

	.item {
		margin-bottom: 18px;
	}

	.clearfix:before,
	.clearfix:after {
		display: table;
		content: "";
	}

	.clearfix:after {
		clear: both
	}

	.box-card {
		margin: 20px;
	}
</style>